package edu.stu.cs.software.family.producer.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers;
import org.springframework.data.domain.ExampleMatcher.StringMatcher;
import org.springframework.stereotype.Component;

import edu.stu.cs.software.family.base.service.impl.GenericManagerImpl;
import edu.stu.cs.software.family.producer.dao.ProducerDao;
import edu.stu.cs.software.family.producer.domain.Producer;
import edu.stu.cs.software.family.producer.service.ProducerManager;
/**
 * 
 * @author Administrator
 *
 */
@Component
public class ProducerManagerImpl extends GenericManagerImpl<Producer, Long> implements ProducerManager{

	ProducerDao producerDao;
	@Override
	public List<Producer> findByName(String producerName) {
		Producer queryObject =new Producer();
		queryObject.setProducerName(producerName);
		ExampleMatcher matcher =ExampleMatcher.matching()
				.withStringMatcher(StringMatcher.CONTAINING)
				.withIgnoreCase(true)
				.withMatcher("producerName", GenericPropertyMatchers.startsWith());
		Example<Producer> ex = Example.of(queryObject, matcher);
		List<Producer> result =this.producerDao.findAll(ex);
		return result;
	}
	
	@Override
	public List<Producer> findByPhone(String phone) {		
		Producer queryObject =new Producer();
		queryObject.setPhone(phone);
		ExampleMatcher matcher =ExampleMatcher.matching()
				.withStringMatcher(StringMatcher.CONTAINING)
				.withIgnoreCase(true)
				.withMatcher("phone", GenericPropertyMatchers.startsWith());
		Example<Producer> ex = Example.of(queryObject, matcher);
		List<Producer> result =this.producerDao.findAll(ex);
		return result;
	}

	@Autowired
	public void setProducerDao(ProducerDao producerDao) {
		this.producerDao = producerDao;
		this.dao=producerDao;
	}
	@Override
    public Producer findByProducerName(String producerName) {
        return this.producerDao.findByProducerName(producerName);
    }
}
